package com.hushao.aimi.service.impl;

import com.hushao.aimi.common.ServerResponse;
import com.hushao.aimi.enumVo.ProductRecommendTypeEnum;
import com.hushao.aimi.enumVo.StatusEnum;
import com.hushao.aimi.repository.RecommendRepository;
import com.hushao.aimi.service.RecommendService;
import com.hushao.aimi.vo.RecommendVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @description: 推荐服务
 * @author: 胡少
 * @create: 2018-06-23 20:22
 **/
@Service
public class RecommendServiceImpl implements RecommendService {
    @Autowired
    private RecommendRepository recommendRepository;

    @Override
    public ServerResponse beanner() {
        List<RecommendVo> list= recommendRepository.findByRecommendCodeAndRecommendStatusOrderBySortOrder(
                ProductRecommendTypeEnum.BANNER.getCode(),
                StatusEnum.RECOMMEND_NORMAL.getStatus())
                .stream().map(r->new RecommendVo(r.getProductId(),r.getRecommendImage()))
                .collect(Collectors.toList());
        return ServerResponse.Success(list);
    }

    @Override
    public ServerResponse other() {
        List<RecommendVo> list= recommendRepository.findByRecommendCodeBetweenAndRecommendStatusOrderBySortOrder(
                ProductRecommendTypeEnum.FULL.getCode(),
                ProductRecommendTypeEnum.HALF.getCode(),
                StatusEnum.RECOMMEND_NORMAL.getStatus())
                .stream().map(r->new RecommendVo(r.getProductId(),r.getRecommendImage(),r.getRecommendTitle(),r.getRecommendCode()))
                .collect(Collectors.toList());
        return ServerResponse.Success(list);
    }
}
